package com.sunnyatwal.kettlebell;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;

public class MainMenuHelper {

	private static final MainMenuHelper instance = new MainMenuHelper();
	
	
	private MainMenuHelper() {}
	
	
	public static MainMenuHelper getInstance() {
		return instance;
	}
	
	
	public void createMenuButtons(final Context c) {
        
        OnClickListener menuClickListener = new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				
				Class<?> myClass = null;
												
				switch(v.getId()) {
				
					case R.id.main_menu_workout:						
						myClass = ManageWorkoutActivity.class;						
						break;
					case R.id.main_menu_clock:
						myClass = ShockClockActivity.class;
						break;
					case R.id.main_menu_log:
						myClass = LogActivity.class;						
						break;
					case R.id.main_menu_settings:
						myClass = SettingsActivity.class;						
						break;
				}	
				
				if (myClass != null && myClass != c.getClass()) {
					Intent intent = new Intent(c, myClass);
					intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
					((Activity) c).startActivity(intent);
				}															
			}
		};
                          
		ImageButton workoutButton = (ImageButton)((Activity) c).findViewById(R.id.main_menu_workout);
		workoutButton.setOnClickListener(menuClickListener);
		workoutButton.setBackgroundResource(R.color.White);
				
        ImageButton clockButton = (ImageButton)((Activity) c).findViewById(R.id.main_menu_clock);
        clockButton.setOnClickListener(menuClickListener);
        clockButton.setBackgroundResource(R.color.White);
        
        ImageButton logButton = (ImageButton)((Activity) c).findViewById(R.id.main_menu_log);
        logButton.setOnClickListener(menuClickListener);
        logButton.setBackgroundResource(R.color.White);
        
        ImageButton settingsButton = (ImageButton)((Activity) c).findViewById(R.id.main_menu_settings);
        settingsButton.setOnClickListener(menuClickListener);	
        settingsButton.setBackgroundResource(R.color.White);
		
        ImageButton button = null;
        
		if ((boolean)c.getClass().equals(ManageWorkoutActivity.class)) {
			button = workoutButton;
		}
		else if ((boolean)c.getClass().equals(ShockClockActivity.class)) {
			button = clockButton;
		}
		else if ((boolean)c.getClass().equals(LogActivity.class)) {
			button = logButton;
		}
		else if ((boolean)c.getClass().equals(SettingsActivity.class)) {
			button = settingsButton;
		}
		
		if (button != null) {
			button.setBackgroundResource(R.color.LightBlue);
		}
	}
	
	
}
